package com.atguigu.jxc.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.GoodsType;
import com.atguigu.jxc.service.GoodsTypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    @PostMapping("/loadGoodsType")
    public String selectGoodsType() {

        return goodsTypeService.selectGoodsType();

    }



    @PostMapping("/save")
    @ResponseBody
    public ServiceVO saveType(String goodsTypeName, Integer pId) {

        return goodsTypeService.saveType(goodsTypeName,pId);
    }

    @PostMapping("/delete")
    @ResponseBody
    public ServiceVO deleteType(Integer  goodsTypeId){
        Boolean aBoolean = goodsTypeService.removeById(goodsTypeId);
       if(aBoolean){
           ServiceVO<Object> objectServiceVO = new ServiceVO<>(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
            return objectServiceVO;
       }
        ServiceVO<Object> objectServiceVO = new ServiceVO<>(ErrorCode.FAIL, ErrorCode.FAIL_DELETE);
       return objectServiceVO;
    }

}
